<?php
	require('./init.php');
	if(isset($_POST['user_id'])){
		$username	=	$_POST['username'];
		$password	=	$_POST['password'];
		$age		=	$_POST['age'];
		$user_id	=	$_POST['user_id'];
		
		$result=$redis->hmset('user:'.$user_id,array('username'=>$username,'password'=>$password,'age'=>$age));
		
		if($result){
			header('location:./list.php');
		}else{
			echo 'error';
		}	
	}else{
		$user_id=$_GET['user_id'];
		$data=$redis->hgetall('user:'.$user_id);
	}
?>
<!doctype html>
<html>
	<head>
		<title></title>
	</head>
	<body>
		<form action="" method="post">
			username <input type='text' name='username' value='<?php echo $data['username']?>'/><br/>
			password <input type='text' name='password' value='<?php echo $data['password']?>'/><br/>
			age <input type='text' name='age' value='<?php echo $data['age']?>'/><br/>
			<input type='hidden' name='user_id' value='<?php echo $data['user_id']?>'>
			<input type='submit' />
		</form>
	</body>
</html>